package com.mes.cloud.web;

import com.mes.cloud.api.dto.request.organization.BaseChannelCustomerRequest;
import com.mes.cloud.api.dto.request.organization.BaseChannelRequest;
import com.mes.cloud.api.dto.request.organization.BaseChannelVoRequest;
import com.mes.cloud.api.dto.request.organization.SysOrganizationChannelRequest;
import com.mes.cloud.api.dto.request.position.SysPositionChannelTypeRequest;
import com.mes.cloud.api.dto.response.BaseChannelDto;
import com.mes.cloud.common.JsonResult;
import com.mes.cloud.service.BaseChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Set;

/**
 * @author ysd
 * @version 2019-08-20 15:48:07
 * @email shaodong.yuan@pactera.com
 */
@Api(tags = "渠道定义", value = "渠道定义接口")
@RestController
@RequestMapping(value = "/baseChannel")
public class BaseChannelController  {

    private BaseChannelService baseChannelService;

    @Autowired
    public BaseChannelController(BaseChannelService baseChannelService) {
        this.baseChannelService = baseChannelService;
    }

    /**
     * 功能: 渠道定义查询所有
     *
     * @param baseChannelRequest
     * @return JsonResult<List<BaseChannelDto>>
     */
    @ApiOperation(value = "渠道定义查询所有", notes = "渠道定义查询所有")
    @PostMapping(value = "/list")
    public JsonResult<List<BaseChannelDto>> list(@RequestBody BaseChannelVoRequest baseChannelRequest) {
        return baseChannelService.list(baseChannelRequest);
    }

    /**
     * 功能: 渠道定义查询所有（岗位）
     *
     * @param sysPositionChannelTypeRequest
     * @return JsonResult<List<BaseChannelDto>>
     */
    @ApiOperation(value = "渠道定义查询所有（岗位）", notes = "渠道定义查询所有（岗位）")
    @PostMapping(value = "/findListByPositionId")
    public JsonResult<List<BaseChannelDto>> findListByPositionId(@Valid @RequestBody SysPositionChannelTypeRequest sysPositionChannelTypeRequest) {
        return baseChannelService.findListByPositionId(sysPositionChannelTypeRequest);
    }

    /**
     * 功能: 渠道定义查询所有（岗位）
     *
     * @param sysOrganizationChannelRequest
     * @return JsonResult<List<BaseChannelDto>>
     */
    @ApiOperation(value = "渠道定义查询所有（组织）", notes = "渠道定义查询所有（组织）")
    @PostMapping(value = "/findListByOrganizationId")
    public JsonResult<List<BaseChannelDto>> findListByOrganizationId(@Valid @RequestBody SysOrganizationChannelRequest sysOrganizationChannelRequest) {
        return baseChannelService.findListByOrganizationId(sysOrganizationChannelRequest);
    }

    /**
     * 功能: 渠道定义查询所有（客户）
     *
     * @param customerChannelRequest
     * @return JsonResult<List<BaseChannelDto>>
     */
    @ApiOperation(value = "渠道定义查询所有（客户）", notes = "渠道定义查询所有（客户）")
    @PostMapping(value = "/findCustomerChannelListByIds")
    public JsonResult<List<BaseChannelDto>> findCustomerChannelListByIds(@Valid @RequestBody BaseChannelCustomerRequest customerChannelRequest) {
        return baseChannelService.findCustomerChannelListByIds(customerChannelRequest);
    }

    /**
     * 功能: 网络覆盖区域_渠道属性
     *
     * @param channelIds
     * @return JsonResult<List<BaseChannelDto>>
     */
    @ApiOperation(value = "网络覆盖区域_渠道属性", notes = "网络覆盖区域_渠道属性")
    @PostMapping(value = "/findCustomerChannelType")
    public JsonResult<List<BaseChannelDto>> findCustomerChannelType(@Valid @RequestBody List<String> channelIds) {
        return baseChannelService.findCustomerChannelType(channelIds);
    }

    /**
     * 功能: 客户详情_渠道树
     *
     * @param channelIds
     * @return JsonResult<List<BaseChannelDto>>
     */
    @ApiOperation(value = "客户详情_渠道树", notes = "客户详情_渠道树")
    @PostMapping(value = "/findChannelListByCustomerId")
    public JsonResult<List<BaseChannelDto>> findChannelListByCustomerId(@Valid @RequestBody List<String> channelIds) {
        return baseChannelService.findChannelListByCustomerId(channelIds);
    }

    /**
     * 功能: 渠道定义新增
     *
     * @param baseChannelRequest
     * @return JsonResult
     */
    @ApiOperation(value = "渠道定义新增", notes = "渠道定义新增")
    @PostMapping(value = "/add")
    public JsonResult<BaseChannelDto> add(@Valid @RequestBody BaseChannelRequest baseChannelRequest) {
        return baseChannelService.add(baseChannelRequest);
    }

    /**
     * 功能: 渠道定义修改
     *
     * @param baseChannelRequest
     * @return JsonResult
     */
    @ApiOperation(value = "渠道定义修改", notes = "渠道定义修改")
    @PostMapping(value = "/update")
    public JsonResult update(@Valid @RequestBody BaseChannelRequest baseChannelRequest) throws Exception {
        return baseChannelService.update(baseChannelRequest);
    }


    /**
     * 功能: 渠道定义查看详情
     *
     * @param id
     * @return JsonResult
     */
    @ApiOperation(value = "渠道定义查看详情", notes = "渠道定义查看详情")
    @ApiImplicitParam(paramType = "Long", name = "id", value = "渠道定义主键", required = true)
    @GetMapping(value = "get/{id}")
    public JsonResult<BaseChannelDto> get(@PathVariable String id) {
        return baseChannelService.get(id);
    }

    /**
     * 功能: 渠道定义禁用启用
     *
     * @param id
     * @param enableFlag
     * @return JsonResult
     */
    @ApiOperation(value = "渠道定义禁用启用", notes = "渠道定义禁用启用")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true),
            @ApiImplicitParam(name = "enableFlag", value = "状态", required = true),
    })
    @GetMapping(value = "/updateEnableFlag/{id}/{enableFlag}")
    public JsonResult updateEnableFlag(@PathVariable String id, @PathVariable String enableFlag) {
        return baseChannelService.updateEnableFlag(id, enableFlag);
    }

    @ApiOperation(value = "查询下级客户类型", notes = "查询下级客户类型")
    @PostMapping(value = "/findChildrenCustomerType")
    public JsonResult<List<String>> findChildrenCustomerType(@RequestBody List<String> channelIds) {
        return baseChannelService.findChildrenCustomerType(channelIds);
    }

    @ApiOperation(value = "查询上级客户类型", notes = "查询下级客户类型")
    @PostMapping(value = "/findParentCustomerType")
    public JsonResult<List<String>> findParentCustomerType(@RequestBody List<String> channelIds) {
        return baseChannelService.findParentCustomerType(channelIds);
    }

    @ApiOperation(value = "通过ids集合查询获得上级渠道id集合", notes = "通过ids集合查询获得上级渠道id集合")
    @PostMapping(value = "/findChannelIdsByIds")
    public JsonResult<List<String>> findChannelIdsByIds(@RequestBody List<String> channelIds) {
        return baseChannelService.findChannelIdsByIds(channelIds);
    }

    @ApiOperation(value = "渠道ids", notes = "渠道ids")
    @PostMapping(value = "/findChannelByIds")
    public JsonResult<List<BaseChannelDto>> findChannelByIds(@Valid @RequestBody Set<String> setChanelId) {
        return baseChannelService.findChannelByIds(setChanelId);
    }

    @ApiOperation(value = "查询子节点", notes = "查询子节点")
    @ApiImplicitParam(paramType = "String", name = "id", value = "渠道定义主键", required = true)
    @GetMapping(value = "/findChildrenIdsById/{id}")
    public JsonResult<List<String>> findChildrenIdsById(@PathVariable String id) {
        return baseChannelService.findChildrenIdsById(id);
    }

    @ApiOperation(value = "查询渠道列表", notes = "查询渠道列表")
    @PostMapping(value = "/findBaseChannelList")
    public JsonResult<List<String>> findBaseChannelList(@Valid @RequestBody BaseChannelCustomerRequest baseChannelCustomerRequest) {
        return baseChannelService.findBaseChannelList(baseChannelCustomerRequest);
    }

    @ApiOperation(value = "查询上级渠道属性", notes = "查询上级渠道属性")
    @PostMapping(value = "/findParentType")
    public JsonResult<List<String>> findParentType(@RequestBody List<String> channelIds) {
        return baseChannelService.findParentType(channelIds);
    }

    @ApiOperation(value = "查询上级第一级渠道", notes = "查询上级第一级渠道")
    @PostMapping(value = "/findParent")
    public JsonResult<BaseChannelDto> findParent(@RequestBody BaseChannelCustomerRequest baseChannelCustomerRequest) {
        return baseChannelService.findParent(baseChannelCustomerRequest);
    }
}
